/*
 * MCP3208.h
 *
 *  Created on: Feb 5, 2013
 *      Author: jonathan whitfield
 */

#ifndef MCP3208_H_
#define MCP3208_H_

#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdint.h>

#define CS PB0
#define SCK PB1
#define MOSI PB2
#define MISO PB3

#define SPI_CLOCK_DIV4 0x00
#define SPI_CLOCK_DIV16 0x01
#define SPI_CLOCK_DIV64 0x02
#define SPI_CLOCK_DIV128 0x03
#define SPI_CLOCK_DIV2 0x04
#define SPI_CLOCK_DIV8 0x05
#define SPI_CLOCK_DIV32 0x06


#define SPI_MODE0 0x00
#define SPI_MODE1 0x04
#define SPI_MODE2 0x08
#define SPI_MODE3 0x0C

class MCP3208
{
	public:
		void begin();
		uint16_t read(uint8_t channel);
		uint16_t read(uint8_t channel, uint16_t count);
		uint16_t read_differential(uint8_t channel);
		uint16_t read_differential(uint8_t channel, uint16_t count);
		uint16_t oversample(uint8_t bits);
		MCP3208();
	private:
		void transmit(uint8_t data);
		uint8_t receive();
		uint8_t readWrite(uint8_t data);
};




#endif /* MCP3208_H_ */
